package ada.com.uhotel;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;
import android.content.pm.PackageManager;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.app.LoaderManager.LoaderCallbacks;

import android.content.CursorLoader;
import android.content.Loader;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;

import android.os.Build;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import ada.com.uhotel.api.entity.Token;
import ada.com.uhotel.api.handler.TokenApi;
import ada.com.uhotel.api.utils.ApiUtils;
import ada.com.uhotel.widget.HlaView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static android.Manifest.permission.READ_CONTACTS;

/**
 * A login screen that offers login via email/password.
 */
@EActivity(R.layout.activity_login)
public class LoginActivity extends AppCompatActivity {


    @ViewById(R.id.hlas)
    LinearLayout hlas;

    @ViewById(R.id.text)
    EditText text;

    @AfterViews
    public void init() {

    }

    @Click(R.id.email_sign_in_button)
    public void click(View view) {
        int num=0;
        int count = hlas.getChildCount();
        for(int i=0;i<count;i++){
           View view1= hlas.getChildAt(i);
            if (view1 instanceof HlaView){
                HlaView hlaView=(HlaView)view1;
                 if (!hlaView.check()){
                     num++;
                 }
            }
        }
        text.setText(""+num);
    }

    @Background
    public void asy() {
        TokenApi service = ApiUtils.get(TokenApi.class);

        Call<Token> call = service.findToken("123", "456");
        try {
            Token token = call.execute().body();
            updateUI(token);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @UiThread
    public void updateUI(Token token) {
        showMesssage(token.getMsg());
    }

    public void showMesssage(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }

}

